﻿#region Copyrights Notice
//©2009 Microsoft Corporation.  All rights reserved.
//This portal design is based on the design and some code from DropThings.com which is also licensed under an MS-PL license.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using Microsoft.InformationSecurity.CISF.Portal.Business.PortalFramework;

//abstract 
public partial class Weblets_AbstractControl : System.Web.UI.UserControl, IWeblet
{
    private IWebletContainer _WebletContainer;
    private XElement m_xmlStorage;

    public virtual void OnInitilize()
    {

    }

    public virtual void OnDisplaySettingChange(bool bDisplay)
    {

    }

    void IWeblet.OnControlInitilize(IWebletContainer webContainer)
    {
        this._WebletContainer = webContainer;
        OnInitilize();
    }

    private XElement State
    {
        get
        {
            if (m_xmlStorage == null)
            {
                string tmpStr = string.Empty;
                tmpStr = this._WebletContainer.Restore();
                if (!tmpStr.Equals(string.Empty))
                    m_xmlStorage = XElement.Parse(tmpStr);
            }
            return m_xmlStorage;
        }
    }

    private void SaveState()
    {
        if (this.State == null)
            return;

        StringBuilder builder = new StringBuilder();
        XmlTextWriter writer = new XmlTextWriter(new StringWriter(builder));
        this.State.WriteTo(writer);

        var xml = builder.ToString();
        this._WebletContainer.Save(xml);
    }

    void IWebletActions.DisplaySettings(bool bDisplay)
    {
        OnDisplaySettingChange(bDisplay);
    }

    void IWebletActions.Minimize()
    {
        //Will be done by Container
    }
    void IWebletActions.Maximize()
    {
        //Will be done by Container
    }
    void IWebletActions.Close()
    {
        //Will be done by Container
    }
    void IWebletActions.MaximizeToFullScreen()
    {
        //Will be done by Container
    }
    void IWebletActions.UpdateSettings()
    {
    }
    protected void SaveSettings_Click(object sender, EventArgs e)
    {
        this._WebletContainer.DisplaySettings(false);
    }

}
